import api from '@/core/Api'
import {Message} from '@/router/urls'

class Service {
  async getPage (params) {
    try {
      let res = await api.aget(Message.getPage(), {
        data: params
      })
      // console.log(res)
      if (res.data.code === 0) {
        return res.data.data
      }
    } catch (e) {
      console.log(e)
    }
    return []
  }
  save (values) {
    return values.get('id') ? api.put(Message.update(values.get('id')), values) : api.post(Message.save(), values)
  }
  delete (id) {
    return api.post(Message.delete(id), {
      _method: 'delete'
    })
  }
  publish (id) {
    return api.post(Message.publish(id))
  }
}

export default new Service()
